package com.Lee.leetcode.q3;

import com.alibaba.fastjson.JSON;
import java.util.Arrays;
import java.util.stream.IntStream;

public class Rotate {

    public static void main(String[] args) {
        int[] arr={-1,-100,3,99};
        rotate(arr,3);
    }
    public static void rotate(int[] nums, int k) {
        int length = nums.length;
        k=k%length;
        int[] reverseArr = reverseArr(nums);
        int[] temp1 = reverseArr(Arrays.copyOfRange(reverseArr, 0, k));
        int[] temp2 = reverseArr(Arrays.copyOfRange(reverseArr, k, length));

        nums= IntStream.concat(Arrays.stream(temp1), Arrays.stream(temp2)).toArray();

        System.out.println(JSON.toJSONString(nums));
    }

    public static int[] reverseArr(int[] arr){
        int length = arr.length;
        int[] reverseArray = new int[length];
        for (int i = 0; i < length; i++) {
            reverseArray[i] = arr[length - i - 1];
        }
        return reverseArray;
    }
}
